#pragma once
#include <memory.h>
#include <string>
#include <algorithm>
namespace firebird {
template <typename T, typename Mutex>
void safe_set(T& dest, T& src, Mutex& mutex) {
	typename Mutex::scoped_lock lock(mutex);
	dest = src;
}

template <typename T>
void safe_set(T& dest, std::string& src) {
	using namespace std;
	size_t size = sizeof(T);
	memset(&dest, 0, size);
	size_t count = min(size-1, src.size());
	memcpy(&dest, (const void*)src.c_str(), count);
}

template <typename T>
void safe_set(T& dest, std::wstring& src) {
	using namespace std;
	size_t size = sizeof(T);
	memset(&dest, 0, size);
	size_t count = min(size-2, src.size()*2);
	memcpy(&dest, (const void*)src.c_str(), count);
}

}